package com.yao.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yao.common.bean.PageQueryBean;
import com.yao.common.helper.ValidateHelper;
import com.yao.common.resp.ApiResponse;
import com.yao.sys.entity.dto.MenuDto;
import com.yao.sys.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单表 Controller
 *
 * @author autoCode
 * @version 1.0.0-SNAPSHOT
 * @date 2020-03-23
 */
@Api(tags = "菜单管理")
@RestController
@RequestMapping(value = "/menu")
public class MenuController {

    private static Logger logger = LoggerFactory.getLogger(MenuController.class);

    @Autowired
    private MenuService menuService;

    @ApiOperation(value = "新增菜单", notes = "新增菜单")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiResponse<Object> add(@RequestBody MenuDto model) {

        menuService.add(model);

        return ApiResponse.success();
    }

    @ApiOperation(value = "修改菜单", notes = "修改菜单")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ApiResponse<Object> update(@RequestBody MenuDto model) {
        return ApiResponse.success();
    }

    @ApiOperation(value = "删除菜单", notes = "逻辑删除菜单")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public ApiResponse<Object> deleteById(@PathVariable("id") Integer id) {
        return ApiResponse.success();
    }

    @ApiOperation(value = "获取菜单详情", notes = "获取菜单详情")
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public ApiResponse<MenuDto> detail(@PathVariable("id") Integer id) {

        ValidateHelper.validateId(id);

        return ApiResponse.success(menuService.getById(id));
    }

    @ApiOperation(value = "获取一级菜单", notes = "获取一级菜单")
    @RequestMapping(value = "/listRoot", method = RequestMethod.GET)
    public ApiResponse<List<MenuDto>> listRoot() {

        return ApiResponse.success(menuService.listRoot());
    }

    @ApiOperation(value = "账号列表(分页)", notes = "账号列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResponse<IPage<MenuDto>> list(@RequestBody PageQueryBean queryBean) {

        return ApiResponse.success(menuService.page(new Page<>(1, 10)));
    }

    @ApiOperation(value = "获取所有菜单", notes = "获取所有菜单")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public ApiResponse<List<MenuDto>> listAll() {
        return ApiResponse.success(menuService.listAllMenu());
    }
}